home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / emulator / uae-0.000 / uae-0 / uae-0.6.0 / autoconf.c < prev    next >
C/C++ Source or Header  |  1996-05-04  |  4KB  |  220 lines

  1.  /* 
  2.   * UAE - The Un*x Amiga Emulator
  3.   * 
  4.   * AutoConfig devices
  5.   *
  6.   * (c) 1995 Bernd Schmidt
  7.   * (c) 1996 Ed Hanway
  8.   */
  9.  
  10. #include "sysconfig.h"
  11. #include "sysdeps.h"
  12.  
  13. #include "config.h"
  14. #include "options.h"
  15. #include "events.h"
  16. #include "memory.h"
  17. #include "custom.h"
  18. #include "newcpu.h"
  19. #include "disk.h"
  20. #include "xwin.h"
  21. #include "autoconf.h"
  22. #include "filesys.h"
  23. #include "hardfile.h"
  24. #include "gfxlib.h"
  25.  
  26. /* Commonly used autoconfig strings */
  27.  
  28. ULONG explibname;
  29.  
  30. /* ROM tag area memory access */
  31.  
  32. static UWORD rtarea[32768];
  33.  
  34. static ULONG rtarea_lget(CPTR) REGPARAM;
  35. static UWORD rtarea_wget(CPTR) REGPARAM;
  36. static UBYTE rtarea_bget(CPTR) REGPARAM;
  37. static void  rtarea_lput(CPTR, ULONG) REGPARAM;
  38. static void  rtarea_wput(CPTR, UWORD) REGPARAM;
  39. static void  rtarea_bput(CPTR, UBYTE) REGPARAM;
  40. static UWORD *rtarea_xlate(CPTR) REGPARAM;
  41.  
  42. addrbank rtarea_bank = {
  43.     rtarea_lget, rtarea_wget, rtarea_bget,
  44.     rtarea_lput, rtarea_wput, rtarea_bput,
  45.     rtarea_xlate, default_check
  46. };
  47.  
  48. UWORD *rtarea_xlate(CPTR addr)
  49. {
  50.     addr &= 0xFFFF;
  51.     return rtarea + (addr >> 1);
  52. }
  53.  
  54. ULONG rtarea_lget(CPTR addr)
  55. {
  56.     addr &= 0xFFFF;
  57.     return (ULONG)(rtarea_wget(addr) << 16) + rtarea_wget(addr+2);
  58. }
  59.  
  60. UWORD rtarea_wget(CPTR addr)
  61. {
  62.     addr &= 0xFFFF;
  63.     return rtarea[addr >> 1];
  64. }
  65.  
  66. UBYTE rtarea_bget(CPTR addr)
  67. {
  68.     UWORD data;
  69.     addr &= 0xFFFF;
  70.     data = rtarea[addr >> 1];
  71.     return addr & 1 ? data : data >> 8;
  72. }
  73.  
  74. void rtarea_lput(CPTR addr, ULONG value) { }
  75. void rtarea_bput(CPTR addr, UBYTE value) { }
  76.  
  77. /* Don't start at 0 -- can get bogus writes there. */
  78. static ULONG trap_base_addr = 0x00F00180; 
  79.  
  80. TrapFunction traps[256];
  81. static int max_trap = 0;
  82.  
  83. void rtarea_wput(CPTR addr, UWORD value) 
  84. {
  85.     /* Save all registers */
  86.     struct regstruct backup_regs = regs;
  87.     ULONG retval = 0;
  88.  
  89.     ULONG func = ((addr  - trap_base_addr) & 0xFFFF) >> 1;
  90.     if(func < max_trap) {
  91.     retval = (*traps[func])();
  92.     } else {
  93.     fprintf(stderr, "illegal emulator trap\n");
  94.     }
  95.     regs = backup_regs;
  96.     regs.d[0] = retval;
  97. }
  98.  
  99. /* some quick & dirty code to fill in the rt area and save me a lot of
  100.  * scratch paper
  101.  */
  102.  
  103. static int rt_addr = 0;
  104. static int rt_straddr = 0xF000/2 - 1;
  105.  
  106. ULONG
  107. addr(int ptr)
  108. {
  109.     return ((ULONG)ptr << 1) + 0x00F00000;
  110. }
  111.  
  112. void
  113. dw(UWORD data)
  114. {
  115.     rtarea[rt_addr++] = data;
  116. }
  117.  
  118. void
  119. dl(ULONG data)
  120. {
  121.     rtarea[rt_addr++] = data >> 16;
  122.     rtarea[rt_addr++] = data;
  123. }
  124.  
  125. /* store strings starting at the end of the rt area and working
  126.  * backward.  store pointer at current address
  127.  */
  128.  
  129. ULONG
  130. ds(char *str)
  131. {
  132.     UWORD data;
  133.     char c;
  134.     int start;
  135.  
  136.     int len = (strlen(str) + 1) >> 1;
  137.     rt_straddr -= len;
  138.     start = rt_straddr;
  139.     
  140.     do {
  141.     data = c = *str++;
  142.     if (c) {
  143.         data <<= 8;
  144.         c = *str++;
  145.         data |= c;
  146.     }
  147.     rtarea[start++] = data;
  148.     } while (c);
  149.     
  150.     return addr(rt_straddr--);
  151. }
  152.  
  153. void
  154. calltrap(ULONG n)
  155. {
  156.     dw(0x33C0);    /* MOVE.W D0,abs32 */
  157.     dl(n*2 + trap_base_addr);
  158. }
  159.  
  160. void
  161. org(ULONG a)
  162. {
  163.     rt_addr = (a - 0x00F00000) >> 1;
  164. }
  165.  
  166. ULONG
  167. here(void)
  168. {
  169.     return addr(rt_addr);
  170. }
  171.  
  172. int
  173. deftrap(TrapFunction func)
  174. {
  175.     int num = max_trap++;
  176.     traps[num] = func;
  177.     return num;
  178. }
  179.  
  180. void
  181. align(int b)
  182. {
  183.     rt_addr = (rt_addr + (b-1)) & ~(b-1);
  184. }
  185.  
  186. /* Ed was right when he wrote that he doesn't trust calling code that
  187.  * Wait()s. This can fail horribly if the Amiga OS switches the task
  188.  * and that task traps again into an emulation routine. I'm not even
  189.  * sure whether we can call AllocMem() safely from here.
  190.  * FIXME: Find a clever solution to prevent these problems.
  191.  */
  192.  
  193. ULONG CallLib(CPTR base, WORD offset)
  194. {
  195.     /* Make tracing through this possible */
  196.     int oldspc = specialflags & SPCFLAG_BRK;
  197.     
  198.     CPTR olda6 = regs.a[6];
  199.     CPTR oldpc = m68k_getpc();
  200.     regs.a[6] = base;
  201.     regs.a[7] -= 4;
  202.     put_long (regs.a[7], 0xF0FFFE);
  203.     m68k_setpc (base + offset);
  204.     MC68000_skip (0xF0FFFE);
  205.     regs.a[6] = olda6;
  206.     m68k_setpc (oldpc);
  207.     specialflags |= oldspc;
  208.     return regs.d[0];
  209. }
  210.  
  211. void
  212. rtarea_init()
  213. {
  214.     explibname = ds("expansion.library");
  215.  
  216.     hardfile_install();
  217.     filesys_install();
  218.     gfxlib_install();
  219. }
  220.